var express = require('express');
var app = express();
var fs = require("fs");

var path=require("path");

var id = 2;
// http://127.0.0.1:8081/deleteUser
app.get('/deleteUser', function (req, res) {

    // First read existing users.
    fs.readFile( __dirname + path.sep+ "users.json", 'utf8', function (err, data) {
        data = JSON.parse( data );
        delete data["user" + id];

        console.log( data );
        res.setHeader('Content-Type', 'text/html; charset=utf8');
        res.end( JSON.stringify(data));
    });
})

var server = app.listen(8081, function () {

    var host = server.address().address
    var port = server.address().port
    console.log("应用实例，访问地址为 http://%s:%s", host, port)

})